"""
MCP工具管理器 - 单例模式，避免重复加载
"""
from typing import Optional
from mcp_tools.SqlTools import get_sql_tools


class McpManager:
    """MCP工具管理器 - 单例模式"""
    
    _instance = None
    _initialized = False
    
    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance
    
    def __init__(self):
        if not self._initialized:
            self.sql_tools = None
            self._initialized = True
    
    async def get_sql_tools(self):
        """获取SQL工具实例（单例）"""
        if self.sql_tools is None:
            print("初始化SQL工具...")
            self.sql_tools = await get_sql_tools()
            print("SQL工具初始化完成")
        return self.sql_tools
    
    def is_initialized(self) -> bool:
        """检查是否已初始化"""
        return self.sql_tools is not None


# 全局单例实例
mcp_manager = McpManager()